//
//  EditNotesCell.m
//  优学荟管理系统
//
//  Created by 星道 on 17/6/29.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "EditNotesCell.h"
#import <SDWebImage/UIButton+WebCache.h>

@implementation EditNotesCell
{
    IBOutlet UIButton *_ImgButton;
    IBOutlet UILabel *_ReadingNotesContent;
    IBOutlet UITextView *_EditContent;

    IBOutlet UIButton *_CommitButton;
    // textView的提示文本
    IBOutlet UILabel *_TextViewPlaceHolder;
}



- (void)awakeFromNib
{
    [super awakeFromNib];

    // 设置内容框的代理
    _EditContent.delegate = self;


    // 得到UserDefault
    NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
    // 得到缓存下的输入框内容
    NSString *Str = [Defaults objectForKey:@"EditNotesCellTextView"];
    // 显示
    _EditContent.text = Str?:@"";

    // 判断要不要隐藏提示文字
    _TextViewPlaceHolder.hidden = Str.length>0?YES:NO;
}



/**
 多行文本代理
 */
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length > 0)
    {
        _TextViewPlaceHolder.hidden = YES;
    }
    else
    {
        _TextViewPlaceHolder.hidden = NO;
    }
}




#pragma mark - 点击事件
/**
 上传
 */
- (IBAction)Commit:(UIButton *)sender
{
    [self.Delegate EditNotesCell:self ClickCommitContentWithButton:sender Content:_EditContent.text];
}



/**
 退出
 */
- (IBAction)Cancle:(UIButton *)sender
{
    [self.Delegate EditNotesCell:self ClickCancleWithButton:sender Content:_EditContent.text];
}




/**
 图片放大
 */
- (IBAction)ImageFull:(UIButton *)sender
{
    [self.Delegate EditNotesCell:self ClickImageWithButton:sender];
}



#pragma mark - Setter
/**
 界面赋值
 */
- (void)setModel:(ReadingNotesModel *)Model
{
    _Model = Model;
    // 图片
    [_ImgButton sd_setImageWithURL:[NSURL URLWithString:Model.imgPath] forState:(UIControlStateNormal) placeholderImage:[UIImage imageNamed:@"btn_add_image_default"]];

    // 心得
    _ReadingNotesContent.text = [@"        " stringByAppendingString:Model.content];
}
@end
